package com.weigee.ktv.v.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.l.d.app.library.util.ResourceUtil;
import com.weigee.ktv.R;

/**
 * Created by 林德 on 2017/4/13 14:58.
 * <p/>
 */
public class WeigeeOthersMsgItemView extends RelativeLayout
{
    private AppCompatTextView m_tvMsg;

    public WeigeeOthersMsgItemView(Context context)
    {
        this(context, null);
    }

    public WeigeeOthersMsgItemView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public WeigeeOthersMsgItemView(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        this.init(context, attrs);
    }

    private void init(Context context, @Nullable AttributeSet attrs)
    {
        LayoutInflater.from(context).inflate(R.layout.wrap_weigee_others_msg_item, this, true);
        ViewGroup parent = (ViewGroup) getChildAt(0);
        parent = (ViewGroup) parent.getChildAt(0);
        m_tvMsg = (AppCompatTextView) parent.getChildAt(0);

        String text = ResourceUtil.string(context, R.string.app_name);
        if (attrs != null)
        {
            TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.WeigeeOthersMsgItemView);
            text = ta.getString(R.styleable.WeigeeOthersMsgItemView_item_others_msg_text);
            ta.recycle();
        }
        m_tvMsg.setText(text);
    }

    public void setText(CharSequence text)
    {
        if (m_tvMsg == null) return;
        m_tvMsg.setText(text);
    }
}
